﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NGinnBPM.Lib.Messages;
using System.Runtime.Serialization;

namespace NGinnBPM.Runtime.Messages
{
    /// <summary>
    /// Task status changed message.
    /// Used by NGinn tasks to report changes of their status to NGinn environment,
    /// which will deliver them to parent tasks.
    /// </summary>
    [Serializable]
    [DataContract]
    public class TaskStatusChanged : ICorrelatedMessage, ITaskInstanceMessage
    {
        public TaskStatusChanged()
        {
            Timestamp = DateTime.Now;
        }

        [DataMember]
        public string SourceTaskInstanceId { get; set; }
        [DataMember]
        public string ParentTaskInstanceId { get; set; }
        [DataMember]
        public string ProcessInstanceId { get; set; }
        [DataMember]
        public string CorrelationId { get; set; }
        [DataMember]
        public DateTime Timestamp { get; set; }
        #region ITaskInstanceMessage Members

        [IgnoreDataMember]
        public string TargetTaskInstanceId
        {
            get {return ParentTaskInstanceId;}
            set {throw new NotImplementedException();}
        }

        #endregion

        public override string ToString()
        {
            return string.Format("{0} [{1}->{2}]", GetType().Name, SourceTaskInstanceId, TargetTaskInstanceId);
        }
    }
}
